package com.uls.zsw.service.impl;

import java.util.List;
import com.uls.common.utils.DateUtils;
import com.uls.zsw.domain.ElectricityManage;
import com.uls.zsw.mapper.ElectricityManageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.uls.zsw.mapper.DormitoryCheckMapper;
import com.uls.zsw.domain.DormitoryCheck;
import com.uls.zsw.service.IDormitoryCheckService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 宿舍查寝Service业务层处理
 * 
 * @author zsw
 * @date 2024-11-23
 */
@Service
public class DormitoryCheckServiceImpl implements IDormitoryCheckService 
{
    @Autowired
    private DormitoryCheckMapper dormitoryCheckMapper;
    @Autowired
    private ElectricityManageMapper electricityManageMapper;


    /**
     * 查询宿舍查寝
     * 
     * @param dormtoryCheckId 宿舍查寝主键
     * @return 宿舍查寝
     */
    @Transactional
    @Override
    public DormitoryCheck selectDormitoryCheckByDormtoryCheckId(Long dormtoryCheckId)
    {
        DormitoryCheck dormitoryCheck=dormitoryCheckMapper.selectDormitoryCheckByDormtoryCheckId(dormtoryCheckId);
        String dn=electricityManageMapper.getDNByDI(dormitoryCheck.getDormitoryId());
        dormitoryCheck.setSelecteddn(dn);
        return dormitoryCheck;
    }

    /**
     * 查询宿舍查寝列表
     * 
     * @param dormitoryCheck 宿舍查寝
     * @return 宿舍查寝
     */
    @Transactional
    @Override
    public List<DormitoryCheck> selectDormitoryCheckList(DormitoryCheck dormitoryCheck)
    {
        System.out.println(dormitoryCheck);
        if(dormitoryCheck!=null){
            Long di=electricityManageMapper.getDIByDN(dormitoryCheck.getSelecteddn());
            dormitoryCheck.setDormitoryId(di);
        };
        List<DormitoryCheck> dormitoryCheckList=dormitoryCheckMapper.selectDormitoryCheckList(dormitoryCheck);
        for(DormitoryCheck dormitoryCheck1:dormitoryCheckList){
            String dn=electricityManageMapper.getDNByDI(dormitoryCheck1.getDormitoryId());
            dormitoryCheck1.setSelecteddn(dn);
        }
        return dormitoryCheckList;
    }

    /**
     * 新增宿舍查寝
     * 
     * @param dormitoryCheck 宿舍查寝
     * @return 结果
     */
    @Transactional
    @Override
    public int insertDormitoryCheck(DormitoryCheck dormitoryCheck)
    {
        dormitoryCheck.setCreateTime(DateUtils.getNowDate());
        Long di=electricityManageMapper.getDIByDN(dormitoryCheck.getSelecteddn());
        dormitoryCheck.setDormitoryId(di);
        return dormitoryCheckMapper.insertDormitoryCheck(dormitoryCheck);
    }

    /**
     * 修改宿舍查寝
     * 
     * @param dormitoryCheck 宿舍查寝
     * @return 结果
     */
    @Transactional
    @Override
    public int updateDormitoryCheck(DormitoryCheck dormitoryCheck)
    {
        dormitoryCheck.setUpdateTime(DateUtils.getNowDate());
        Long di=electricityManageMapper.getDIByDN(dormitoryCheck.getSelecteddn());
        dormitoryCheck.setDormitoryId(di);
        return dormitoryCheckMapper.updateDormitoryCheck(dormitoryCheck);
    }

    /**
     * 批量删除宿舍查寝
     * 
     * @param dormtoryCheckIds 需要删除的宿舍查寝主键
     * @return 结果
     */
    @Override
    public int deleteDormitoryCheckByDormtoryCheckIds(Long[] dormtoryCheckIds)
    {
        return dormitoryCheckMapper.deleteDormitoryCheckByDormtoryCheckIds(dormtoryCheckIds);
    }

    /**
     * 删除宿舍查寝信息
     * 
     * @param dormtoryCheckId 宿舍查寝主键
     * @return 结果
     */
    @Override
    public int deleteDormitoryCheckByDormtoryCheckId(Long dormtoryCheckId)
    {
        return dormitoryCheckMapper.deleteDormitoryCheckByDormtoryCheckId(dormtoryCheckId);
    }
}
